package jdk8;


import java.util.Arrays;
import java.util.List;

@FunctionalInterface
public interface Supplier<T> {
    T get();
}

class Car {
    public static Car create(final Supplier<Car> supplier){
        return supplier.get();
    }

    public static void collide(Car car){
        System.out.println("collide = [" + car.toString() + "]");
    }

    public void follow(Car another){
        System.out.println("Following the [" + another.toString() + "]");
    }

    public void repair(){
        System.out.println("Repaired " + this.toString());
    }

    public static void main(String[] args) {
        Car car = Car.create(Car::new);
        List<Car> cars = Arrays.asList(car);

        cars.forEach(Car::collide);
        Car police = Car.create(Car::new);
        cars.forEach(police::follow);
    }
}
